package com.gr.controller;

import com.gr.entity.Book;
import com.gr.entity.Category;
import com.gr.service.BookService;
import com.gr.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;
    @Autowired
    private CategoryService categoryService;
    @RequestMapping("/showMain")
    public String showMain(Model model){
        List<Book> recommend = bookService.selectByRecommend();
        List<Book> soleNum= bookService.selectBySaleNum();
        List<Book> groDate= bookService.selectByGroDate();
        List<Book> groAndSNum=bookService.selectByGroDateAndSaleNum();
        List<Category> cateList = categoryService.selectAll();
        model.addAttribute("cateList",cateList);
        model.addAttribute("groAndSNum",groAndSNum);
        model.addAttribute("groDate",groDate);//最近上架图书
        model.addAttribute("soleNum",soleNum);//热销
        model.addAttribute("rec",recommend);//编辑推荐
        return "forward:/main/main.jsp";
    }
    @RequestMapping("/selectOne")
    public String selectOne(Integer id,Model model){
        Book book = bookService.selectOne(id);
        model.addAttribute("book",book);
        return "/main/product.jsp";
    }
}
